home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 41 / Amiga Format CD41 (1999-06)(Future Publishing)(GB)[!][issue 1999-07].iso / -seriously_amiga- / programming / other / sounddt41src / debug.h < prev    next >
C/C++ Source or Header  |  1999-04-19  |  3KB  |  103 lines

  1. #ifndef DEBUG_H
  2. #define DEBUG_H
  3. /*
  4. **    $VER: Debug.h 2.1 (19.10.97)
  5. **
  6. **    Copyright (C) 1995,96,97 Bernardo Innocenti. All rights reserved.
  7. **
  8. **    Use 4 chars wide TABs to read this file
  9. **
  10. **    Some handy debug macros which are automatically excluded when the
  11. **    DEBUG preprocessor sysmbol is not defined. To make debug executables,
  12. **    link with debug.lib or any module containing the kprintf() function.
  13. **
  14. **    Here is a short description of the macros defined below:
  15. **
  16. **    ILLEGAL
  17. **        Output an inline "ILLEGAL" 68K opcode, which will
  18. **        be interpreted as a breakpoint by most debuggers.
  19. **
  20. **    DBPRINTF
  21. **        Output a formatted string to the debug console. This
  22. **        macro uses the debug.lib kprintf() function by default.
  23. **
  24. **    ASSERT(x)
  25. **        Do nothing if the expression <x> evalutates to a
  26. **        non-zero value, output a debug message otherwise.
  27. **
  28. **    ASSERT_VALID(x)
  29. **        Checks if the expression <x> points to a valid
  30. **        memory location, and outputs a debug message
  31. **        otherwise. A NULL pointer is considered VALID.
  32. **
  33. **    ASSERT_VALIDNO0(x)
  34. **        Checks if the expression <x> points to a valid
  35. **        memory location, and outputs a debug message
  36. **        otherwise. A NULL pointer is considered INVALID.
  37. **
  38. **    DB(x)
  39. **        Compile the expression <x> when making a debug
  40. **        executable, leave it out otherwise.
  41. */
  42.  
  43. #ifdef DEBUG_ME
  44.  
  45.     /* Needed for TypeOfMem() */
  46.     #ifndef  PROTO_EXEC_H
  47.     #include <proto/exec.h>
  48.     #endif /* PROTO_EXEC_H */
  49.  
  50.     #if defined(__SASC)
  51.  
  52.         extern void __builtin_emit (int);
  53.         #define ILLEGAL __builtin_emit(0x4AFC)
  54.         STDARGS extern void kprintf (const char *, ...);
  55.  
  56.     #elif defined(__GNUC__)
  57.  
  58.         /* Currently, there is no kprintf() function in libamiga.a */
  59.         #define kprintf printf
  60.  
  61.         /* GCC doesn't accept asm statemnts in the middle of an
  62.          * expression such as "a ? b : asm(something)".
  63.          */
  64.         #define ILLEGAL illegal()
  65.         static inline int illegal(void) { asm ("illegal"); return 0; }
  66.         extern void STDARGS FORMATCALL(printf,1,2) kprintf (const char *, ...);
  67.  
  68.     #else
  69.         #error Please add compiler specific definitions for your compiler
  70.     #endif
  71.  
  72.     #if defined(__SASC) || defined (__GNUC__)
  73.  
  74.         /* common definitions for ASSERT and DB macros */
  75.  
  76.         #define DBPRINTF kprintf
  77.  
  78.         #define ASSERT(x) ( (x) ? 0 :                                        \
  79.             ( DBPRINTF ("\x07%s, %ld: assertion failed: " #x "\n",            \
  80.             __FILE__, __LINE__) , ILLEGAL ) );
  81.  
  82.         #define ASSERT_VALID(x) ( ((((APTR)(x)) == NULL) ||                    \
  83.             (((LONG)(x) > 1024) &&    TypeOfMem ((APTR)(x)))) ? 0 :            \
  84.             ( DBPRINTF ("\x07%s, %ld: bad address: " #x " = $%lx\n",        \
  85.             __FILE__, __LINE__, (APTR)(x)) , ILLEGAL ) );
  86.  
  87.         #define ASSERT_VALIDNO0(x) ( (((LONG)(x) > 1024) &&                    \
  88.             TypeOfMem ((APTR)(x))) ? 0 :                                    \
  89.             ( DBPRINTF ("\x07%s, %ld: bad address: " #x " = $%lx\n",        \
  90.             __FILE__, __LINE__, (APTR)(x)) , ILLEGAL ) );
  91.  
  92.         #define DB(x) x
  93.     #endif
  94.  
  95. #else
  96.     #define ASSERT_VALID(x)
  97.     #define ASSERT_VALIDNO0(x)
  98.     #define ASSERT(x)
  99.     #define DB(x)
  100. #endif /* DEBUG */
  101.  
  102. #endif /* !DEBUG_H */
  103.